import requests
from lxml import etree


def find(name):
    url = 'https://www.yinhuadm.xyz/vch/' + name + '.html'

    headers = {
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36',
        'referer': 'https://www.yinhuadm.xyz/',
    }
    # url = 'https://player.mcue.cc/yinhua/?url=MCZY-1646yYUKyaIaFSIMJUfISwbiTSEXFIV6gwgRfujXxJ_6cUSgApqOL-ya2eZYZQXlRKBfB_9fvtRLvjJcBVr3x_vIgePtjLqzIPEdCF3RvY4GpWuF1QbS&next=https://www.yinhuadm.xyz/p/4870-1-3.html&title=%E6%96%97%E7%A0%B4%E8%8B%8D%E7%A9%B9%E5%B9%B4%E7%95%AA%20%E7%AC%AC02%E9%9B%86%E5%9C%A8%E7%BA%BF%E6%92%AD%E6%94%BE'
    r = requests.get(url, headers=headers)

    print(r)

    r = r.text

    print(r)

    r = etree.HTML(r)

    total = r.xpath('.//div[@class="module-items module-card-items"]/div')

    print(len(total))
    re = {"ok": True,
          "videos": [
              # {
              # "id": "1", "title": "海边日出", "author": "用户A",
              # "duration": "15s", "publish_time": "2025-09-01",
              # "cover_url": "/static/picture/demo_cover.jpg",
              # "page_url": "https://www.douyin.com/video/xxxx",
              # "play_url": "https://www.douyin.com/video/xxxx/play",
              # "download_url": "https://example.com/download/xxxx"
              # }
          ]}



    for i in total:
        video = {'title': (i.xpath('.//strong/text()'))[0], 'time': '', 'picture': '', 'url': '', 'total': []}
        print(video['title'])
        video['time'] = (i.xpath('.//div[@class="module-info-item-content"]/text()'))[0]
        # print(video['time'])
        # video['total'] = (i.xpath('.//div[@class="module-item-note"]/text()'))[0]
        # print(video['total'])
        # video['picture'] = (i.xpath('.//div[@class="module-item-pic"]/img[@class="lazy lazyload"]/@src'))[0]
        # print(video['picture'])
        video['url'] = 'https://www.yinhuadm.xyz'+(i.xpath('.//a[@class="play-btn-o"]/@href'))[0]
        # print(video['url'])

        # te = requests.get(video['url'], headers=headers).text
        # te = etree.HTML(te)

        # t = te.xpath('.//div[@class="module-play-list-content module-play-list-base"]')
        # print(len(t),t)

        # for j in t:
        #     ar = (j.xpath('.//a/span/text()'))
            # video['total'].append(len(ar))
        # print(video['total'])

        re['videos'].append(video)
        #
        # totals = requests.get(video['url'], headers=headers).text
        # print(totals)


        # print(video)
    print(re)

    return re

if __name__ == '__main__':
    find('斗破苍穹')
